import { DefendSkillPropListPanel } from "../copy/defend/DefendSkillPropListPanel";
import { SRaceUseSkill } from "../../../../Message/Public/SRaceUseSkill";
import { SPoint } from "../../../../Message/Public/SPoint";
import { KeyCode } from "../../../../com/gengine/keyBoard/KeyCode";
import { ItemData } from "../../resource/info/ItemData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DragEvent } from "../../../../com/mui/events/DragEvent";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { ShortcutsItem } from "../shortcuts/ShortcutsItem";
import { MsgManager } from "../../manager/MsgManager";
import { Game } from "../../Game";
import { SkillConfig } from "../../resource/SkillConfig";
import { ThingUtil } from "../../scene/layer/utils/ThingUtil";
import { GameMapUtil } from "../../scene/map/GameMapUtil";
import { RolePlayer } from "../../scene/player/entity/RolePlayer";
import { ESkillTargetSelect } from "../../../../Message/Public/ESkillTargetSelect";
import { CursorManager } from "../../manager/CursorManager";
import { AIManager } from "../../scene/ai/AIManager";
type int = number;
//class RaceCopySkillPanel
    
    export  class RaceCopySkillPanel extends DefendSkillPropListPanel
    {
        constructor(arg1: int=5)
        {
            super(arg1);
            this._throwSkill = new SRaceUseSkill();
            this._throwSkill.onlyRemove = true;
            this._throwSkill.mousePoint = new SPoint();
            return;
        }

        public set canUseSkill(arg1: Boolean)
        {
            this._canUseSkill = arg1;
            return;
        }

        public useSkillByShortcutKey(arg1: uint): void
        {
            var loc4=null;
            var loc1=-1;
            var loc2=false;
            var loc5=arg1;
            switch (loc5) 
            {
                case KeyCode.N1:
                {
                    loc1 = 0;
                    loc2 = false;
                    break;
                }
                case KeyCode.N2:
                {
                    loc1 = 1;
                    loc2 = false;
                    break;
                }
                case KeyCode.N3:
                {
                    loc1 = 2;
                    loc2 = false;
                    break;
                }
                case KeyCode.N4:
                {
                    loc1 = 3;
                    loc2 = false;
                    break;
                }
                case KeyCode.Q:
                {
                    loc1 = 0;
                    loc2 = true;
                    break;
                }
                case KeyCode.W:
                {
                    loc1 = 1;
                    loc2 = true;
                    break;
                }
                case KeyCode.E:
                {
                    loc1 = 2;
                    loc2 = true;
                    break;
                }
                case KeyCode.R:
                {
                    loc1 = 3;
                    loc2 = true;
                    break;
                }
            }
            if (loc1 == -1) 
            {
                return;
            }
            var loc3;
            if ((loc3 = _propVec[loc1]) == null || loc3.itemData == null) 
            {
                return;
            }
            if (loc2) 
            {
                if ((loc4 = loc3.itemData as ItemData) != null) 
                {
                    this._throwSkill.skillUid = loc4.uid;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.RaceCopyUseSkill, this._throwSkill));
                }
            }
            else 
            {
                this.useSkillItem(loc3);
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc2=null;
            super.createChildren();
            var loc1=0;
            while (loc1 < _skillMaxNum) 
            {
                loc2 = _propVec[loc1];
                loc2.isDragAble = true;
                loc2.isDropAble = false;
                loc2.isThrowAble = true;
                loc2.addChild(this.getShortcutText(loc1));
                loc2.addChild(this.getThrowText(RaceCopySkillPanel.ThrowKeys[loc1] as string));
                loc2.addEventListener(DragEvent.Event_Throw_goods, this.throwSkillHandler);
                ++loc1;
            }
            return;
        }

        /* internal  */getShortcutText(arg1: int): GTextFiled
        {
            var loc1=ObjCreate.createGTextField("", 2, 2, 20, 20);
            var loc2=loc1.defaultTextFormat;
            loc2.size = 12;
            loc1.defaultTextFormat = loc2;
            loc1.text = (arg1 + 1).toString();
            loc1.mouseEnabled = false;
            return loc1;
        }

        /* internal  */getThrowText(arg1: string): GTextFiled
        {
            var loc1=GlobalStyle.textFormat2;
            loc1.size = 11;
            loc1.align = flash.text.TextFormatAlign.RIGHT;
            var loc2=ObjCreate.createGTextField("", -2, 22, 40, 20, null, loc1);
            loc2.text = arg1 + Language.getString(80510);
            loc2.mouseEnabled = false;
            return loc2;
        }

        /* internal  */throwSkillHandler(arg1: DragEvent): void
        {
            var loc1=new SRaceUseSkill();
            var loc2=arg1.dragSouce as ItemData;
            this._throwSkill.skillUid = loc2.uid;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RaceCopyUseSkill, this._throwSkill));
            return;
        }

        protected /* override */ onItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as ShortcutsItem;
            this.useSkillItem(loc1);
            return;
        }

        /* internal  */useSkillItem(arg1: ShortcutsItem): void
        {
            if (!this._canUseSkill) 
            {
                MsgManager.showRollTipsMsg(Language.getString(80164));
                return;
            }
            if (arg1.playingEffect) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60054));
            }
            else if (arg1.dragSource) 
            {
                if (arg1.itemData) 
                {
                    this.useSkillHandler(arg1.itemData);
                }
            }
            return;
        }

        public clearUseLingDong(): void
        {
            Game.scene.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSceneClickHandler);
            this._skill = null;
            return;
        }

        /* internal  */useSkillHandler(arg1: ItemData): void
        {
            if (arg1 == null || arg1.itemInfo.item == null) 
            {
                return;
            }
            var loc1=arg1.itemInfo.item;
            var loc2=SkillConfig.instance.getInfoByName(arg1.itemInfo.item.effect);
            if (loc2 == null) 
            {
                return;
            }
            this._skill = new SRaceUseSkill();
            this._skill.onlyRemove = false;
            this._skill.mousePoint = new SPoint();
            if (ThingUtil.selectEntity != null) 
            {
                this._skill.entityIds = [ThingUtil.selectEntity.entityInfo.entityInfo.entityId];
            }
            this._skill.skillUid = arg1.uid;
            var loc3;
            if ((loc3 = GameMapUtil.getTilePoint(RolePlayer.instance.x, RolePlayer.instance.y)) != null) 
            {
                this._skill.mousePoint.x = loc3.x;
                this._skill.mousePoint.y = loc3.y;
            }
            if (loc2.targetSelect != ESkillTargetSelect._ESkillTargetSelectNeedTarget) 
            {
                if (loc2.targetSelect == ESkillTargetSelect._ESkillTargetSelectMouse) 
                {
                    Game.scene.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSceneClickHandler, false, 9999, true);
                    CursorManager.showCursor(CursorManager.PointMask);
                    this._lastTarget = AIManager.lastTarget;
                    return;
                }
            }
            else if (ThingUtil.selectEntity == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60089));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.RaceCopyUseSkill, this._skill));
            return;
        }

        /* internal  */onSceneClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._skill == null) 
            {
                return;
            }
            CursorManager.hideCursor();
            var loc1=GameMapUtil.getTilePoint(Game.scene.mouseX, Game.scene.mouseY);
            this._skill.mousePoint.x = loc1.x;
            this._skill.mousePoint.y = loc1.y;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RaceCopyUseSkill, this._skill));
            this.clearUseLingDong();
            return;
        }

        public get lastTarget(): Object
        {
            return this._lastTarget;
        }

        public static /* const */ThrowKeys: Array<any>=["Q", "W", "E", "R"];

        protected /* var */_throwSkill: SRaceUseSkill;

        /* internal */ /* var */_canUseSkill: Boolean=true;

        /* internal */ /* var */_skill: SRaceUseSkill;

        /* internal */ /* var */_lastTarget: Object;
    }
